package com.credit.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.credit.common.ServerResponse;
import com.credit.pojo.analysisChart;
import com.credit.pojo.certificate;
import com.credit.pojo.development;
import com.credit.pojo.environmental;
import com.credit.pojo.financialBenefit;
import com.credit.pojo.occupationalHealth;
import com.credit.pojo.otherProducts;
import com.credit.pojo.professionalWork;
import com.credit.pojo.qualification;
import com.credit.pojo.qualityControl;
import com.credit.pojo.socialContribution;
import com.credit.service.IBusinessCreditService;
import com.credit.utlis.ImgUpload;

/**
 * 商业信用信息
 * @author Administrator
 *
 */
@CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
@RestController
@Controller
public class BusinessCreditController {

	@Autowired
	private IBusinessCreditService businessCreditService;
	
	
	/**
	 * 显示质量管理体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectQualityControl.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectQualityControl(int id) {
		
		return businessCreditService.selectQualityControl(id);
	}
	
	
	/**
	 * 增加质量管理体系
	 * @param q
	 * @return
	 */
	@RequestMapping(value = "addQualityControl.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addQualityControl(qualityControl q) {
		
		return businessCreditService.insertQualityControl(q);
	}
	
	/**
	 * 修改质量管理体系
	 * @param q
	 * @return
	 */
	@RequestMapping(value = "upQualityControl.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upQualityControl(qualityControl q) {
		
		return businessCreditService.updateQualityControl(q);
	}
	
	
	/**
	 * 删除质量管理体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delQualityControl.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delQualityControl(int id) {
		
		return businessCreditService.deleteQualityControl(id);
	}
	
	
	
	
	
	
	/**
	 * 显示环境管理体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectEnvironmental.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectEnvironmental(int id) {
		
		return businessCreditService.selectEnvironmental(id);
	}
	
	
	/**
	 * 增加环境管理体系
	 * @param e
	 * @return
	 */
	@RequestMapping(value = "addEnvironmental.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addEnvironmental(environmental e) {
		
		return businessCreditService.insertEnvironmental(e);
	}
	
	/**
	 * 修改环境管理体系
	 * @param e
	 * @return
	 */
	@RequestMapping(value = "upEnvironmental.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upEnvironmental(environmental e) {
		
		return businessCreditService.updateEnvironmental(e);
	}
	
	
	/**
	 * 删除环境管理体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delEnvironmental.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delEnvironmental(int id) {
		
		return businessCreditService.deleteEnvironmental(id);
	}
	
	
	
	
	
	
	/**
	 * 显示其他产品体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectOtherProducts.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectOtherProducts(int id) {
		
		return businessCreditService.selectOtherProducts(id);
	}
	
	
	/**
	 * 增加其他产品体系
	 * @param o
	 * @return
	 */
	@RequestMapping(value = "addOtherProducts.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addOtherProducts(otherProducts o) {
		
		return businessCreditService.insertOtherProducts(o);
	}
	
	/**
	 * 修改其他产品体系
	 * @param o
	 * @return
	 */
	@RequestMapping(value = "upOtherProducts.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upOtherProducts(otherProducts o) {
		
		return businessCreditService.updateOtherProducts(o);
	}
	
	
	/**
	 * 删除其他产品体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delOtherProducts.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delOtherProducts(int id) {
		
		return businessCreditService.deleteOtherProducts(id);
	}

	
	
	
	
	/**
	 * 显示职业健康安全管理体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectOccupationalHealth.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectOccupationalHealth(int id) {
		
		return businessCreditService.selectOccupationalHealth(id);
	}
	
	
	/**
	 * 增加职业健康安全管理体系
	 * @param o
	 * @return
	 */
	@RequestMapping(value = "addOccupationalHealth.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addOccupationalHealth(occupationalHealth o) {
		
		return businessCreditService.insertOccupationalHealth(o);
	}
	
	/**
	 * 修改职业健康安全管理体系
	 * @param o
	 * @return
	 */
	@RequestMapping(value = "upOccupationalHealth.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upOccupationalHealth(occupationalHealth o) {
		
		return businessCreditService.updateOccupationalHealth(o);
	}
	
	
	/**
	 * 删除职业健康安全管理体系
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delOccupationalHealth.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delOccupationalHealth(int id) {
		
		return businessCreditService.deleteOccupationalHealth(id);
	}
	
	
	
	
	
	
	
	/**
	 * 显示资质管理情况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectQualification.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectQualification(int id) {
		
		return businessCreditService.selectQualification(id);
	}
	
	
	/**
	 * 增加资质管理情况
	 * @param q
	 * @return
	 */
	@RequestMapping(value = "addQualification.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addQualification(qualification q) {
		
		return businessCreditService.insertQualification(q);
	}
	
	/**
	 * 修改资质管理情况
	 * @param q
	 * @return
	 */
	@RequestMapping(value = "upQualification.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upQualification(qualification q) {
		
		return businessCreditService.updateQualification(q);
	}
	
	
	/**
	 * 删除资质管理情况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delQualification.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delQualification(int id) {
		
		return businessCreditService.deleteQualification(id);
	}
	
	
	
	
	
	/**
	 * 显示业务情况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectProfessionalWork.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectProfessionalWork(int id) {
		
		return businessCreditService.selectProfessionalWork(id);
	}
	
	
	/**
	 * 增加业务情况
	 * @param p
	 * @return
	 */
	@RequestMapping(value = "addProfessionalWork.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addProfessionalWork(professionalWork p) {
		
		return businessCreditService.insertProfessionalWork(p);
	}
	
	/**
	 * 修改业务情况
	 * @param p
	 * @return
	 */
	@RequestMapping(value = "upProfessionalWork.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upProfessionalWork(professionalWork p) {
		
		return businessCreditService.updateProfessionalWork(p);
	}
	
	
	/**
	 * 删除业务情况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delProfessionalWork.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delProfessionalWork(int id) {
		
		return businessCreditService.deleteProfessionalWork(id);
	}
	
	
	
	
	
	
	/**
	 * 显示发展能力
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectDevelopment.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectDevelopment(int id) {
		
		return businessCreditService.selectDevelopment(id);
	}
	
	
	/**
	 * 增加发展能力
	 * @param d
	 * @return
	 */
	@RequestMapping(value = "addDevelopment.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addDevelopment(development d) {
		
		return businessCreditService.insertDevelopment(d);
	}
	
	/**
	 * 修改发展能力
	 * @param d
	 * @return
	 */
	@RequestMapping(value = "upDevelopment.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upDevelopment(development d) {
		
		return businessCreditService.updateDevelopment(d);
	}
	
	
	/**
	 * 删除发展能力
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delDevelopment.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delDevelopment(int id) {
		
		return businessCreditService.deleteDevelopment(id);
	}
	
	
	
	
	
	
	/**
	 * 显示社会贡献状况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectSocialContribution.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectSocialContribution(int id) {
		
		return businessCreditService.selectSocialContribution(id);
	}
	
	
	/**
	 * 增加社会贡献状况
	 * @param s
	 * @return
	 */
	@RequestMapping(value = "addSocialContribution.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addSocialContribution(socialContribution s) {
		
		return businessCreditService.insertSocialContribution(s);
	}
	
	/**
	 * 修改社会贡献状况
	 * @param d
	 * @return
	 */
	@RequestMapping(value = "upSocialContribution.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upSocialContribution(socialContribution s) {
		
		return businessCreditService.updateSocialContribution(s);
	}
	
	
	/**
	 * 删除社会贡献状况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delSocialContribution.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delSocialContribution(int id) {
		
		return businessCreditService.deleteSocialContribution(id);
	}
	
	
	
	
	
	

	/**
	 * 显示财务效益状况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectFinancialBenefit.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectFinancialBenefit(int id) {
		
		return businessCreditService.selectFinancialBenefit(id);
	}
	
	
	/**
	 * 增加财务效益状况
	 * @param f
	 * @return
	 */
	@RequestMapping(value = "addFinancialBenefit.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addFinancialBenefit(financialBenefit f) {
		
		return businessCreditService.insertFinancialBenefit(f);
	}
	
	/**
	 * 修改财务效益状况
	 * @param f
	 * @return
	 */
	@RequestMapping(value = "upFinancialBenefit.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upFinancialBenefit(financialBenefit f) {
		
		return businessCreditService.updateFinancialBenefit(f);
	}
	
	
	/**
	 * 删除财务效益状况
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delFinancialBenefit.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delFinancialBenefit(int id) {
		
		return businessCreditService.deleteFinancialBenefit(id);
	}
	
	
	
	
	
	
	/**
	 * 显示企业证书
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "selectCertificate.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse selectCertificate(int id) {
		
		return businessCreditService.selectCertificate(id);
	}
	
	
	/**
	 * 增加企业证书
	 * @param c
	 * @return
	 */
	@RequestMapping(value = "addCertificate.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse addCertificate(certificate c,@RequestParam(value = "file", required = false) MultipartFile photo,HttpServletRequest request) {
		try {
			String url = ImgUpload.PictureUpload(photo, request);
			c.setUrl(url);
		} catch (IOException e) {
		
			e.printStackTrace();
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		return businessCreditService.insertCertificate(c);
	}
	
	/**
	 * 修改企业证书
	 * @param c
	 * @return
	 */
	@RequestMapping(value = "upCertificate.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse upCertificate(certificate c,@RequestParam(value = "file", required = false) MultipartFile photo,HttpServletRequest request) {
		try {
			String url = ImgUpload.PictureUpload(photo, request);
			c.setUrl(url);
		} catch (IOException e) {
		
			e.printStackTrace();
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		return businessCreditService.updateCertificate(c);
	}
	
	
	/**
	 * 删除企业证书
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delCertificate.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse delCertificate(int id) {
		
		return businessCreditService.deleteCertificate(id);
	}
	
	
	
	/**
	 * type    0:流动债务构成分析图     1:非流动债务构成图
	 *         2:流动资产构成图       其他:非流动资产构成图
	 * @param a
	 * @param photo
	 * @param request
	 * @param type
	 * @return
	 */
	@RequestMapping(value = "updateAnalysisChart.do", method = RequestMethod.POST)
	@ResponseBody
	public ServerResponse updateAnalysisChart(analysisChart a,@RequestParam(value = "file", required = false) MultipartFile photo,HttpServletRequest request,Integer type) {
		try {
			String url = ImgUpload.PictureUpload(photo, request);
			if(type == 0) {
				a.setFiowdebt(url);
			}else if(type == 2) {
				a.setFiowasset(url);
			}else if(type == 1){
				a.setReceivables(url);
			}
			
		} catch (IOException e) {
		
			e.printStackTrace();
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		return businessCreditService.updateAnalysisChart(a);
	}
	
	
	
	
	
	
}
